package team.seekers.hula.course.course.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.course.entity.vo.CourseListVO;
import team.seekers.hula.course.course.entity.vo.CourseInfoVO;
import team.seekers.hula.course.course.entity.vo.CourseManageListVO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 知桨表(Course)实体类
 *
 * @author GH
 * @since 2022-04-30 18:07:15
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(CourseDOField.TABLE_NAME)
public class CourseDO extends BaseDO {
    private static final long serialVersionUID = 1L;

    /**
     * 知桨id
     */
    @TableId(value = CourseDOField.ID, type = IdType.ASSIGN_ID)
    private String id;
    /**
     * 知桨名字
     */
    @TableField(CourseDOField.NAME)
    private String name;
    /**
     * 知桨主理人id
     */
    @TableField(CourseDOField.USER_ID)
    private String userId;
    /**
     * 知桨主理团队id
     */
    @TableField(CourseDOField.TEAM_ID)
    private String teamId;
    /**
     * 知桨封面
     */
    @TableField(CourseDOField.COVER)
    private String cover;
    /**
     * 知桨背景图
     */
    @TableField(CourseDOField.BACKGROUND)
    private String background;
    /**
     * 知桨简介
     */
    @TableField(CourseDOField.DESCRIPTION)
    private String description;
    /**
     * 知桨介绍
     */
    @TableField(CourseDOField.INTRODUCTION)
    private String introduction;
    /**
     * 课程价格
     */
    @TableField(CourseDOField.PRICE)
    private Double price;
    /**
     * 课程状态（未开放、更新中、已完结）
     */
    @TableField(CourseDOField.STATUS)
    private Integer status;

    @TableField(CourseDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(value = CourseDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = CourseDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static List<CourseListVO> DOListToVOList(List<CourseDO> courseDOS) {
        ArrayList<CourseListVO> courseListVOS = new ArrayList<>();
        for (CourseDO courseDO : courseDOS) {
            CourseListVO courseListVO = new CourseListVO();
            BeanUtils.copyProperties(courseDO,courseListVO);
            courseListVOS.add(courseListVO);
        }
        return courseListVOS;
    }

    /**除了sectionCount之外的其他属性转换*/
    public CourseInfoVO toVO() {
        return CourseInfoVO.builder()
                .id(this.id)
                .name(this.name)
                .cover(this.cover)
                .description(this.description)
                .introduction(this.introduction)
                .price(this.price)
                .status(this.status)
                .build();
    }

    /**除了teacherName、contents之外的其他属性转换*/
    public CourseListVO toPageVO() {
        return CourseListVO.builder()
                .id(this.id)
                .name(this.name)
                .cover(this.cover)
                .price(this.price)
                .status(this.status)
                .description(this.description)
                .build();
    }

    public static List<CourseManageListVO> toMangeListVOList(List<CourseDO> courseDOS){
        ArrayList<CourseManageListVO> courseManageListVOS = new ArrayList<>();
        for (CourseDO courseDO : courseDOS) {
            CourseManageListVO courseManageListVO = new CourseManageListVO();
            BeanUtils.copyProperties(courseDO,courseManageListVO);
            courseManageListVOS.add(courseManageListVO);
        }
        return courseManageListVOS;
    }
}
